<?php

namespace App\Http\Controllers\Api\V1\Site;

use Illuminate\Http\Request;
use Biz\Services\Site\SiteRegistrationService;
use Biz\Requests\Site\StoreRegistrationRequest;
use Biz\Requests\Site\UpdateRegistrationRequest;
use Biz\Resources\Site\SiteRegistrationResource;
use Lumen\Http\Resources\Json\DataResourceResponse;
use Laravel\Lumen\Routing\Controller as BaseController;
use Biz\Resources\Site\SiteRegistrationResourceCollection;

/**
 * RegistrationController.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class RegistrationController extends BaseController
{
    /**
     * @var mixed
     */
    protected $service;

    /**
     * RegistrationController constructor.
     *
     * @param SiteRegistrationService $service
     */
    public function __construct(SiteRegistrationService $service)
    {
        $this->service = $service;
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $results = $this->service->index($request);

        return new SiteRegistrationResourceCollection($results);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param StoreRegistrationRequest $request
     *
     * @return \Illuminate\Http\Response
     */
    public function store(StoreRegistrationRequest $request)
    {
        $site = $this->service->create($request->all());

        return new SiteRegistrationResource($site);
    }

    /**
     * Display the specified resource.
     *
     * @param string $id
     *
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $site = $this->service->show($id);

        return new SiteRegistrationResource($site);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param UpdateRegistrationRequest $request
     * @param string                    $id
     *
     * @return \Illuminate\Http\Response
     */
    public function update(UpdateRegistrationRequest $request, $id)
    {
        $site = $this->service->edit($id, $request->all());

        return new SiteRegistrationResource($site);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param string $id
     *
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $result = $this->service->remove($id);

        return new DataResourceResponse($result);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param string $id
     * @param string $locale
     *
     * @return \Illuminate\Http\Response
     */
    public function deleteTranslations($id, $locale)
    {
        $result =  $this->service->deleteTranslations($id, $locale);

        return new DataResourceResponse($result);
    }
}
